<?php

use Illuminate\Database\Seeder;
use App\Http\Models\Menu;
use App\Http\Models\User;

class InitializeTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        if (!Menu::query()->where('name', '权限管理')->exists()) {
            $id = Menu::query()->insertGetId([
                                                 'name' => '权限管理',
                                                 'pid' => 0,
                                                 'route' => '',
                                                 'created_at' => date("Y-m-d H:i:s"),
                                                 'updated_at' => date("Y-m-d H:i:s")
                                             ]);
            Menu::query()->create([
                                      'name' => '用户管理',
                                      'pid' => $id,
                                      'route' => 'admin.user.index',
                                      'created_at' => date("Y-m-d H:i:s"),
                                      'updated_at' => date("Y-m-d H:i:s")
                                  ]);
            Menu::query()->create([
                                      'name' => '角色管理',
                                      'pid' => $id,
                                      'route' => 'admin.roles.index',
                                      'created_at' => date("Y-m-d H:i:s"),
                                      'updated_at' => date("Y-m-d H:i:s")
                                  ]);
            Menu::query()->create([
                                      'name' => '权限组管理',
                                      'pid' => $id,
                                      'route' => 'admin.permission.index',
                                      'created_at' => date("Y-m-d H:i:s"),
                                      'updated_at' => date("Y-m-d H:i:s")
                                  ]);
            Menu::query()->create([
                                      'name' => '菜单管理',
                                      'pid' => $id,
                                      'route' => 'admin.menu.index',
                                      'created_at' => date("Y-m-d H:i:s"),
                                      'updated_at' => date("Y-m-d H:i:s")
                                  ]);
        }

        if (!User::query()->where('email', 'admin@admin.com')->exists()) {
            User::query()->create([
                                      'email' => 'admin@admin.com',
                                      'name' => '超级管理员',
                                      'password' => '$2y$10$QOtlXJ5mTdOJtOh9VVXGIekS2k2OzNdiMcq.F5Cnlr8CnWdq980ha',
                                      'administrator' => 1,
                                      'status' => 1,
                                      'creator_id' => 1,
                                      'created_at' => date("Y-m-d H:i:s"),
                                      'updated_at' => date("Y-m-d H:i:s")
                                  ]);
        }
    }
}
